package code.rocky.chapter01;

import java.util.Date;

public class Suggest18 {
    public static void main(String[] args) {
        // “String”是一个字符串，字符串又继承了对象,那当然是返回true了。
        boolean b1 = "String" instanceof Object;
        // 类对象就是它的实例
        boolean b2 = new String() instanceof String;
        // Object 是父类, 其对象当然不是String类的实例
        boolean b3 = new Object() instanceof String;
        // 编译失败 instance 只能用于对象的判断,不能用于基本类型的判断
        // boolean b4 = 'A' instanceof Character;
        // 左边是false ,直接返回 false
        boolean b5 = null instanceof String;
        // 即使做类型转换也还是 null
        boolean b6 = (String) null instanceof String;
        // Date 和 String 没有继承或者实现关系, 编译通不过
        // boolean b7 = new Date() instanceof String;
        // 编译通过, T 是 Object, "t instanceof Date" -> "Object instanceof Date"
        boolean b8 = new GenericClass<String>().isDateInstance("");
        System.out.println("b1 " + b1);
        System.out.println("b2 " + b2);
        System.out.println("b3 " + b3);
        System.out.println("b5 " + b5);
        System.out.println("b6 " + b6);
        System.out.println("b8 " + b8);
    }

    static class GenericClass<T> {
        // 判断是否是Date类型
        public boolean isDateInstance(T t) {
            return t instanceof Date;
        }
    }
}
